﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Class_Program
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlDataReader reader = null;
            try
            {
                //查询全部游戏信息
                //创建插入的SQL语句
                string Sql = "select ID,Name,Price,Stock,Price*Stock as Total from Games";
                reader = DBHelper.GetDatareader(sql);
                Console.WriteLine("序号\t游戏名称\t游戏价格\t库存数量\t小计");
                Console.WriteLine("+--------------------------------------------");
                while (reader.Read())
                {
                    Console.WriteLine("{0}\t{1}\t{2:C}元\t{3}\t{4:C}元",
                    reader["ID"],
                    reader["Name"],
                    reader["Price"],
                    reader["Stock"],
                    reader["Total"]
                    );
                }
                reader.Close();
            Console.WriteLine("+--------------------------");
            //统计总金额
            string totalSql = "select sum(Price*Stock) from  Games";
            Console.WriteLine("游戏总金额:{0:C}元", DBHelper.ExecuteScalar(totalSql));
            }
            catch (Exception ex)
            {
            //监测到异常，进行异常处理，防止应用程序崩溃，打印信息提示用户
        Console.WriteLine("加载产品列表时出现异常，请联系管理员！\n原因： "+ex.Message);
            }
        }
    }
}
